<%@ page language="java" import="java.util.*" contentType="text/html"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>新增试卷</title>
<script charset="utf-8" src='<c:url value="/js/jquery.min.js"></c:url>'></script>
<script type="text/javascript" src='<c:url value="/js/boot.js"></c:url>'></script>
<script type="text/javascript"
	src='<c:url value="/js/rqfui/rqfui.js"></c:url>'></script>
<style>
html, body {
	margin: 0;
	padding: 0;
	font-family: "微软雅黑";
}

li {
	list-style: none;
}

a {
	text-decoration: none;
}

.Basic_course_content {
	width: 1920px;
	width: 100%;
}

.Basic_course_content_content {
	width: 1280px;
	margin: 0 auto;
}

.Basic_course_content_content_content {
	width: 780px;
	margin-left: 104px;
	margin-top: 24px;
	text-align: left;
}

.Basic_course_content_content_content_title {
	color: #b8b8b8;
	font-size: 16px;
	padding-bottom: 1px;
	border-bottom: 2px solid #2459aa;
	font-weight: 800;
}

.Basic_course_content_content_content_title ul {
	padding: 0;
	margin: 10px;
}

.Basic_course_content_content_content_title li {
	display: inline-block;
	margin-right: 55px;
}

.Basic_course_content_content_content_title div {
	display: inline-block;
	height: 20px;
	width: 20px;
	border-radius: 50%;
	background: #b8b8b8;
}

.Basic_course_content_content_content_title li>div>span {
	color: white;
	z-index: 1;
	position: relative;
	left: 6px;
	top: -2px;
	font-weight: 800;
	font-size: 13px;
}

.Basic_course_content_content_content_content {
	padding: 25px 0;
}

.Basic_course_content_content_content_content>ul>li {
	padding: 16px 0;
}

.Basic_course_content_content_content_content>ul {
	margin: 0;
	padding: 0;
	margin-bottom: 16px;
}

.Basic_course_content_content_content_content>ul>li>div>span {
	/*float: left;*/
	font-size: 16px;
	padding: 4px 0;
}

.Basic_course_content_content_content_content>ul>li>div>span>font {
	color: #ff0000;
}

.Basic_course_content_content_content_content>ul>li>div>input {
	width: 420px;
	padding: 5px 0;
	padding-left: 5px;
}

.Basic_course_content_content_content_content>ul>li>div>select {
	padding: 5px 0;
	padding-left: 5px;
}

.Basic_course_content_content_content_content>ul>li>div>textarea {
	width: 420px;
	padding: 5px;
	margin-top: 5px;
}

.Basic_course_content_content_content_content>ul>li>div>select>option {
	padding: 3px;
}

.Basic_course_baocun {
	width: 78px;
	height: 32px;
	text-align: center;
	background: #2459aa;
	color: #fff;
	font-size: 16px;
	line-height: 32px;
	border-radius: 3px;
	margin-left: 92px;
	display: inline-block;
	margin-right: 30px;
	cursor: pointer;
}

.fixedWidth {
	width: 22px;
}

.inlineDisplay {
	display: inline-block;
}

/*  */
.mini-buttonedit-border {
	height: 29px;
}

.mini-buttonedit-icon {
	margin-top: 6px !important;
}

.mini-buttonedit-button {
	height: 29px !important;
}

.mini-buttonedit-border, .mini-textbox-border {
	border-radius: 0px !important;
}

.mini-buttonedit-input {
	height: 29px !important;
}

.mini-buttonedit-border {
	border-color: #b3acac;
}
/*  */
</style>
</head>
<body>
	<div class="Basic_course_content">
		<div class="Basic_course_content_content">
			<div class="Basic_course_content_content_content">
				<div class="Basic_course_content_content_content_title">
					<ul>
						<li style="color: #2459aa;">
							<div style="color: #2459aa; background: #2459aa;">
								<span style="">1</span>
							</div> <span>新建试卷</span>
						</li>
						<li>
							<div>
								<span>2</span>
							</div> <span>试卷组装</span>
						</li>
						<li>
							<div>
								<span>3</span>
							</div> <span>设置试卷</span>
						</li>
					</ul>
				</div>
				<div class="Basic_course_content_content_content_content">
					<ul>
						<li>
							<div>
								<span><font>*</font> 试卷名称：</span> <input type="text"
									id="paperName" />
							</div>
						</li>
						<li>
							<div>
								<span><font>*</font> 试卷类型：</span> <select id="select_paper_type"
									style="color: #2459aa; width: 200px; cursor: pointer;">
								</select>
								<!-- <span style="color:#b8b8b8;position:relative;left:-200px;font-size:14px;">请选择</span> -->
							</div>
						</li>
						<li>
							<div>
								<span><font>&nbsp;</font> 所属课程：</span> <input id="lookup2"
									name="look" class="mini-lookup"
									style="width: 432px; height: 32px;" textField="class_name"
									valueField="id" popupWidth="auto" popup="#gridPanel"
									grid="#datagrid1" multiSelect="true" value="" text="" />
								<div id="gridPanel" class="mini-panel" title="header"
									iconCls="icon-add" style="width: 450px; height: 250px;"
									showToolbar="true" showCloseButton="true" showHeader="false"
									bodyStyle="padding:0" borderStyle="border:0">
									<div property="toolbar"
										style="padding: 5px; padding-left: 8px; text-align: center;">
										<div style="float: left; padding-bottom: 2px;">
											<span>课程：</span> <input id="keyText" class="mini-textbox"
												style="width: 160px;" onenter="onSearchClick" /> <a
												class="mini-button" onclick="onSearchClick">查询</a> <a
												class="mini-button" onclick="onClearClick">清除</a>
										</div>
										<div style="float: right; padding-bottom: 2px;">
											<a class="mini-button" onclick="onCloseClick">确定</a>
										</div>
										<div style="clear: both;"></div>
									</div>
									<div id="datagrid1" class="mini-datagrid"
										style="width: 100%; height: 100%;" borderStyle="border:0"
										showPageSize="false" showPageIndex="false" url=''>
										<div property="columns">
											<div type="checkcolumn"></div>
											<div field="class_name" width="120" headerAlign="center"
												allowSort="true">课程</div>
											<div field="creater" width="120" headerAlign="center"
												allowSort="true">编制人</div>
											<div field="createTime" width="100" headerAlign="center"
												dateFormat="yyyy-MM-dd" allowSort="true">创建日期</div>
										</div>
									</div>
								</div>
							</div>
						</li>
						<li>
							<div>
								<span><font>*</font> 试卷时长：</span> <input id="time" type="text"
									style="border: 1px solid #ccc; width: 200px;"
									onkeyup="this.value=this.value.replace(/\D/g,'')"
									onafterpaste="this.value=this.value.replace(/\D/g,'')">
								<span>分钟</span>
							</div>
						</li>
						<li id="edit_article">
							<div class="Basic_course_modify">
								<span><font>*</font> 打分方式：</span>
								<div class="inlineDisplay">
									<input type="radio" style="" id="auto" name="grading_way"
										value="1"><label for="auto" class="fixedWidth ">自动</label for="">
								</div>
								<div class="inlineDisplay">
									<input type="radio" style="" id="hand" name="grading_way"
										value="0"><label for="hand" class="fixedWidth">手动</label for="">
								</div>
								<span style="font-size: 14px; color: red;">（说明：试卷设置为自动打分将不能添加解答题型）</span>
							</div>
						</li>
					</ul>
					<a class="Basic_course_baocun" href="javascript:save()">保存</a> <a
						class="Basic_course_baocun" href="javascript:next()">下一步</a>
				</div>
			</div>
		</div>
	</div>
</body>
<script>
	mini.parse();
	mini_debugger = false;
	var rootPath = '${rootPath}';
	var datagrid1 = mini.get("datagrid1");
	var keyText = mini.get("keyText");
	var filterHelper = gridFilter();
	var lookup2 = mini.get("lookup2");
	var isSave = false;
	var paperId;
	var grading_way = "";
	$("#select_course_type").click(function() {
		$(".select_course_type_content").show();
	});
	$(".cancel").click(function() {
		$(".select_course_type_content").hide();
	});
	$(function() {
		getTypeList();
	})
	$("#select_paper_type").change(function() {
		var value = $("#select_paper_type").val();
		onSearchClick(value);
	});
	function onSearchClick(str) {
		var key = keyText.getValue();
		filterHelper.clearFilterData();
		if (key != "") {
			var filterdata = filterHelper.formFilterData("class_name", key, '',
					'CONTAIN', 'AND');
			filterHelper.addFilterData(filterdata);
		}
		if (str != "") {
			var filterdata = filterHelper.formFilterData("class_id", str, '',
					'CONTAIN', 'AND');
			filterHelper.addFilterData(filterdata);
		}
		loadGrid1();
	}
	function loadGrid1() {
		var filterData = filterHelper.getFilterData();
		var postData = new Object();
		if (filterData != null || filterData.length > 0) {
			postData.filterdata = mini.encode(filterData);
		}
		var url = "<c:url value='/question/courseList' />";
		datagrid1.load(url);
		datagrid1.load(postData);
	}
	function onCloseClick(e) {

		lookup2.hidePopup();
	}
	function onClearClick(e) {
		lookup2.deselectAll();
		keyText.setValue();
		filterHelper.clearFilterData();
		loadGrid1();
	}

	function getTypeList() {
		var url = rootPath + "/class/typeList";
		$.ajax({
			url : url,
			method : "post",
			dataType : "json",
			data : {},
			success : function(data) {
				var htmStr = "<option>请选择</option>";
				if (data) {
					for (var i = 0; i < data.length; i++) {
						htmStr += "<option value = \""+data[i].id+"\">"
								+ data[i].name + "</option>"
					}
				}
				$("#select_paper_type").html(htmStr);
			}
		});

	}

	function save(callBackfunction) {
		var url = rootPath + "/testPaper/add";
		var paperName = $("#paperName").val();//试卷名称
		if (!paperName) {
			top.commonTools.showTip("请填写试卷名称!", 2);
			return;
		}
		var class_id = $("#select_paper_type").val();//试卷类型
		if (class_id == "请选择") {
			top.commonTools.showTip("请选择类型!", 2);
			return;
		}
		var course_id = lookup2.getValue();
		var course_name = lookup2.getText();//所属课程
		if (!course_name) {
			/* top.commonTools.showTip("请选择所属课程!", 2);
			return; */
		}
		var time = $("#time").val();//答题时间
		if (!time) {
			top.commonTools.showTip("请设置答题时间!", 2);
			return;
		}
		var handleWay = $("input[name='grading_way']:checked").val();//打分方式
		if (!handleWay) {
			top.commonTools.showTip("请设置打分方式!", 2);
			return;
		}
		if (handleWay == 1) {
			grading_way = "auto";
		} else {
			grading_way = "hand";
		}
		var map = new Object;
		map.name = paperName;
		map.class_id = class_id;
		map.courseId = course_id;
		map.courseName = course_name;
		map.time = time;
		map.isAuto = handleWay;
		var jsonData = JSON.stringify(map);
		$.ajax({
			url : url,
			method : "post",
			dataType : "json",
			data : {
				'data' : jsonData
			},
			success : function(data) {
				if (data) {
					isSave = true;
					top.commonTools.showTip("保存成功", 1);
					paperId = data.oid;
					if (callBackfunction) {
						callBackfunction();
					}
				}
			},
			error : function() {
				top.commonTools.showTip("失败", 2);
			},
			complete : function() {

			}
		});
	}

	function next() {
		if(isSave){
			location.href = rootPath + "/testPaper/packages/" + grading_way
			+ "/" + paperId;
		}else{
			save(function() {
				location.href = rootPath + "/testPaper/packages/" + grading_way
						+ "/" + paperId;
			});
		}
	}
</script>
</html>